<?php
/**
 * Created by PhpStorm.
 * User: 清行
 * Date: 2019/3/18
 * Time: 21:46
 */
namespace xiaokang;
use Illuminate\Support\Facades\DB;
use xiaokang\Route;
use xiaokang\Register;
class Start{

    public static $classMap = array();
    static public function run()
    {
//        $Register = new Register();
        Register::offsetSet('db','\xiaokang\Model');

//        dump($_SERVER);
//        $R = new Request();
//        dump($R);


        $route = new Route();
        $ctrlClass = $route->ctrl;
        $action = $route->action;
        $ctrlfile = C_PATH.$ctrlClass.'.php';
        $ctrlClass = '\\APP\\Controller\\'.$ctrlClass;


        if (is_file($ctrlfile))
        {
            include $ctrlfile;
            $ctrl = new $ctrlClass();
            $ctrl->$action();
        }else{
            throw new \Exception('找不到控制器'.$ctrlfile);
        }
    }
    static public function autoload($class)
    {
        if (isset($classMap[$class]))
        {
            return true;
        }else{
            $file = str_replace('\\','/',BASEDIR.'/'.$class.'.php');
            if (is_file($file))
            {
                require_once $file;
                self::$classMap[$class]=$class;
            }else{
                return false;
            }
        }
    }
}